package com.xugui.learn.pay.pojo.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 支付状态枚举类
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum PayStatus {

    WAITING(0, "待支付"),
    SUCCESS(1, "成功"),
    FAILED(2, "失败"),
    CANCELED(3, "已取消"),
    REFUND(4, "已退款");

    private Integer code;

    private String desc;

    /**
     * 根据 code 获取支付状态的枚举类
     *
     * @param code 支付状态的 code
     * @return 支付状态的枚举类
     */
    public static PayStatus getByCode(Integer code) {
        for (PayStatus item : values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }
}